(import
  (except (rnrs base) let-values map error)
  (only (guile) lambda* λ command-line)
  (srfi srfi-1)
  (fileio))


(define find-number
  (λ (numbers)
    (let iter ([factors-outer numbers] [factors-inner numbers] [rest-numbers numbers])
      (cond
       [(null? factors-outer) (error "tried all combinations")]
       [(null? factors-inner)
        ;; can now discard the first number
        (iter (cdr factors-outer) rest-numbers (cdr rest-numbers))]
       [else
        (let ([fac1 (car factors-outer)] [fac2 (car factors-inner)])
          (cond
           [(= (+ fac1 fac2) 2020) (* fac1 fac2)]
           [else
            (iter factors-outer (cdr factors-inner) rest-numbers)]))]))))


(define main
  (λ (cmd-line-args)
    (let* ([lines (get-lines-from-file (cadr cmd-line-args))]
           [numbers (map string->number lines)])
      (find-number numbers))))


(simple-format (current-output-port)
               "~a\n"
               (main (command-line)))
